package org.scripts.watcher.gui;

import org.farming.Patches;
import org.farming.plants.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

public class PatchPanel extends JPanel
{
    private final Color COLOR_DISEASE = new Color(255, 153,  51);//Orange
    private final Color COLOR_DEFAULT = new Color(238, 238, 238);//Greyey White
    private final Color COLOR_DEAD    = new Color(204,   0,  51);//Red
    private final Color COLOR_READY   = new Color(51,  153,   0);//Green
    private final Color COLOR_UNKNOWN = new Color(153, 0,   204);//Purple
    
    private Patches p;
	public PatchPanel(Patches p)
    {
        this.p = p;
		initComponents();
        setBorder(new TitledBorder(p.toString()));
        update();
	}
    //Dummy method required for jfd
    public PatchPanel()
    {
    	initComponents();
        setBorder(new TitledBorder("Test Panel"));
	}
    public void update()
    {
        Plants plant = p.plantType();                 //Identifies the patch type
        int curByte = p.getByte();                      //Holds all our infomation about the patch
        Plants.PlantEnum plantType = plant.getPlant(curByte);  //Identifies the type of plant in the patch
        plantLabel.setText(plantType.toString());                           //Update plant type
        stageLabel.setText(plant.getStage(curByte)+"/"+plantType.stages()); //Update plant stage
        switch (plant.getState(curByte))
        {
            case EMPTY:
                statusLabel.setText("Empty");
                statusLabel.setBackground(COLOR_DEFAULT);
                break;
            case GROWING:
                statusLabel.setText("Growing");
                statusLabel.setBackground(COLOR_DEFAULT);
                break;
            case WATERED:
                statusLabel.setText("Watered");
                statusLabel.setBackground(COLOR_DEFAULT);
                break;
            case DISEASED:
                statusLabel.setText("Diseased");
                statusLabel.setBackground(COLOR_DISEASE);
                break;
            case DEAD:
                statusLabel.setText("Dead");
                statusLabel.setBackground(COLOR_DEAD);
                break;
            case READY:
                statusLabel.setText("Ready");
                statusLabel.setBackground(COLOR_READY);
                break;
            case BRANCHES:
                statusLabel.setText("Branches Ready");
                statusLabel.setBackground(COLOR_READY);
                break;
            case CHECK_HEALTH:
                statusLabel.setText("Check Health");
                statusLabel.setBackground(COLOR_READY);
                break;
            case CHOPPED:
                statusLabel.setText("Chopped");
                statusLabel.setBackground(COLOR_DEFAULT);
                break;
            default:
                statusLabel.setText("Unknown");
                statusLabel.setBackground(COLOR_UNKNOWN);
        }
    }

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		label7 = new JLabel();
		plantLabel = new JLabel();
		label2 = new JLabel();
		statusLabel = new JLabel();
		label5 = new JLabel();
		stageLabel = new JLabel();

		//======== this ========
		setBorder(new TitledBorder("text"));
		setLayout(new GridBagLayout());
		((GridBagLayout)getLayout()).columnWidths = new int[] {5, 1, 5, 50, 5, 0, 5, 50, 5, 0, 5, 50, 5, 0};
		((GridBagLayout)getLayout()).rowHeights = new int[] {5, 0, 5, 0};
		((GridBagLayout)getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
		((GridBagLayout)getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 1.0E-4};

		//---- label7 ----
		label7.setText("Plant:");
		label7.setHorizontalAlignment(SwingConstants.RIGHT);
		add(label7, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(0, 0, 0, 0), 0, 0));

		//---- plantLabel ----
		plantLabel.setText("-");
		plantLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));
		plantLabel.setHorizontalTextPosition(SwingConstants.CENTER);
		plantLabel.setHorizontalAlignment(SwingConstants.CENTER);
		add(plantLabel, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(0, 0, 0, 0), 6, 0));

		//---- label2 ----
		label2.setText("Status:");
		label2.setHorizontalAlignment(SwingConstants.RIGHT);
		add(label2, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(0, 0, 0, 0), 0, 0));

		//---- statusLabel ----
		statusLabel.setText("-");
		statusLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));
		statusLabel.setHorizontalTextPosition(SwingConstants.CENTER);
		statusLabel.setHorizontalAlignment(SwingConstants.CENTER);
		statusLabel.setOpaque(true);
		add(statusLabel, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(0, 0, 0, 0), 6, 0));

		//---- label5 ----
		label5.setText("Stage:");
		label5.setHorizontalAlignment(SwingConstants.RIGHT);
		add(label5, new GridBagConstraints(9, 1, 1, 1, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(0, 0, 0, 0), 0, 0));

		//---- stageLabel ----
		stageLabel.setText("-");
		stageLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));
		stageLabel.setHorizontalTextPosition(SwingConstants.CENTER);
		stageLabel.setHorizontalAlignment(SwingConstants.CENTER);
		add(stageLabel, new GridBagConstraints(11, 1, 1, 1, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(0, 0, 0, 0), 6, 0));
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	private JLabel label7;
	private JLabel plantLabel;
	private JLabel label2;
	private JLabel statusLabel;
	private JLabel label5;
	private JLabel stageLabel;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
}
